/**
 * FivesBlock.java
 * Handles the beads in a single row which are in the five's column.
 * Copyright (c) 2012 The Javanauts
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
 * persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package edu.utsa.cs.cs4953_2012.abacus;

import java.awt.Graphics;

/**
 * Represents a single row of beads in the five's column.
 * 
 */
public final class FivesBlock extends BeadBlock {
	/**
	 * Constructor.
	 * 
	 * @param x
	 *            The horizontal position of the block, in pixels.
	 * @param y
	 *            The vertical position of the block, in pixels.
	 * @param width
	 *            The width of the block, in pixels.
	 * @param height
	 *            The height of the block, in pixels.
	 */
	public FivesBlock(int x, int y, int width, int height) {
		super(x, y, width, height);
	}
	
	/**
	 * Draws the block onto the current graphics context.
	 * 
	 * @param g
	 *            The graphics context the block will draw to.
	 */
	@Override
	public void Draw(Graphics g) {
		g.draw3DRect(position.width, position.height, size.width, size.height,
				true);
		int textX = position.width + (size.width / 4);
		int textY = position.height + (size.height / 2);
		int repositionX = textX - 40;
		int repositionY = textY - 21;

		if (!usingText)
			g.drawImage(beads[getValue()], repositionX, repositionY, null);
		else {
			// As there's only 4 possible values, a simple switch ensures best
			// results.
			switch (getValue()) {
			case 0:
				g.drawString("000        ", textX, textY);
				break;
			case 1:
				g.drawString("00        0", textX, textY);

				break;
			case 2:
				g.drawString("0        00", textX, textY);
				break;
			case 3:
				g.drawString("        000", textX, textY);
				break;
			}
		}
	}
	
	/**
	 * Changes the block's state to a new one.
	 * 
	 * @param value
	 *            The value of the block's new state.
	 */
	@Override
	public void setValue(int value) {
		if (value < 0 && value > 3)
			throw new IllegalArgumentException(
					"Argument must be between 0 and 3, inclusive.");
		this.value = value;
	}
}
